namespace InventoryManagement
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Data.SqlClient;
	using System.Text;
	
	
	public class Data_Kunjungan : BaseTable
	{
		
		#region Static SQL String Members
		/// <remarks>This field represents the full SELECT string for the table Data Kunjungan, with the WHERE clause.</remarks>
		internal static string _SQL_Select = "SELECT [ID], [wfStatus], [Tanggal], [ID_DataCabang], [KunjunganRutin], [TroubleCabang], [DeploymentUnit], [LainLain], [DeskripsiKunjungan], [PICHO] FROM [dbo].[Data Kunjungan] WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the full SELECT string for the table Data Kunjungan, with the WHERE clause.</remarks>
		internal static string _SQL_SelectByParam = "SELECT [ID], [wfStatus], [Tanggal], [ID_DataCabang], [KunjunganRutin], [TroubleCabang], [DeploymentUnit], [LainLain], [DeskripsiKunjungan], [PICHO] FROM [dbo].[Data Kunjungan] WHERE isnull(convert(varchar(36),[ID]),\'true\')=isnull(convert(varchar(36),@ID),isnull(convert(varchar(36),[ID]),\'true\')) AND isnull(convert(varchar,[wfStatus]),\'true\')=isnull(convert(varchar,@wfStatus),isnull(convert(varchar,[wfStatus]),\'true\')) AND isnull(convert(varchar,[Tanggal]),\'true\')=isnull(convert(varchar,@Tanggal),isnull(convert(varchar,[Tanggal]),\'true\')) AND isnull(convert(varchar(36),[ID_DataCabang]),\'true\')=isnull(convert(varchar(36),@ID_DataCabang),isnull(convert(varchar(36),[ID_DataCabang]),\'true\')) AND isnull(convert(varchar,[KunjunganRutin]),\'true\')=isnull(convert(varchar,@KunjunganRutin),isnull(convert(varchar,[KunjunganRutin]),\'true\')) AND isnull(convert(varchar,[TroubleCabang]),\'true\')=isnull(convert(varchar,@TroubleCabang),isnull(convert(varchar,[TroubleCabang]),\'true\')) AND isnull(convert(varchar,[DeploymentUnit]),\'true\')=isnull(convert(varchar,@DeploymentUnit),isnull(convert(varchar,[DeploymentUnit]),\'true\')) AND isnull(convert(varchar,[LainLain]),\'true\')=isnull(convert(varchar,@LainLain),isnull(convert(varchar,[LainLain]),\'true\')) AND isnull(convert(varchar,[DeskripsiKunjungan]),\'true\')=isnull(convert(varchar,@DeskripsiKunjungan),isnull(convert(varchar,[DeskripsiKunjungan]),\'true\')) AND isnull(convert(varchar,[PICHO]),\'true\')=isnull(convert(varchar,@PICHO),isnull(convert(varchar,[PICHO]),\'true\')) ";
		
		/// <remarks>This field represents the full INSERT INTO string for the table Data Kunjungan.</remarks>
		internal static string _SQL_Insert = @"INSERT INTO [dbo].[Data Kunjungan] ([ID], [wfStatus], [Tanggal], [ID_DataCabang], [KunjunganRutin], [TroubleCabang], [DeploymentUnit], [LainLain], [DeskripsiKunjungan], [PICHO]) VALUES(@ID, @wfStatus, @Tanggal, @ID_DataCabang, @KunjunganRutin, @TroubleCabang, @DeploymentUnit, @LainLain, @DeskripsiKunjungan, @PICHO) ";
		
		/// <remarks>This field represents the full UPDATE string for the table Data Kunjungan, with the WHERE clause.</remarks>
		internal static string _SQL_Update = @"UPDATE [dbo].[Data Kunjungan] SET [ID] = @ID, [wfStatus] = @wfStatus, [Tanggal] = @Tanggal, [ID_DataCabang] = @ID_DataCabang, [KunjunganRutin] = @KunjunganRutin, [TroubleCabang] = @TroubleCabang, [DeploymentUnit] = @DeploymentUnit, [LainLain] = @LainLain, [DeskripsiKunjungan] = @DeskripsiKunjungan, [PICHO] = @PICHO WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the DELETE string for the table Data Kunjungan, with the WHERE clause.</remarks>
		internal static string _SQL_Delete = "DELETE FROM [dbo].[Data Kunjungan] WHERE [ID]=@ID ";
		#endregion
		
		#region Tables Members
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID;
		
		[DisplayName("ID")]
		[Category("Primary Key")]
		public System.Nullable<System.Guid> ID
		{
			get
			{
				try
				{
					return _ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID", err);
				}
			}
			set
			{
				try
				{
					_ID = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _wfStatus;
		
		[DisplayName("wf Status")]
		[Category("Column")]
		public string wfStatus
		{
			get
			{
				try
				{
					return _wfStatus;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting wfStatus", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_wfStatus = value;
					}
					else
					{
						throw new OverflowException("Error setting wfStatus, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting wfStatus", err);
				}
			}
		}
		
		/// <remarks>SQL Type:datetime - </remarks>
		private System.Nullable<System.DateTime> _Tanggal;
		
		[DisplayName("Tanggal")]
		[Category("Column")]
		public System.Nullable<System.DateTime> Tanggal
		{
			get
			{
				try
				{
					return _Tanggal;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Tanggal", err);
				}
			}
			set
			{
				try
				{
					_Tanggal = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Tanggal", err);
				}
			}
		}
		
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID_DataCabang;
		
		[DisplayName("ID_Data Cabang")]
		[Category("Foreign Key")]
		public System.Nullable<System.Guid> ID_DataCabang
		{
			get
			{
				try
				{
					return _ID_DataCabang;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_DataCabang", err);
				}
			}
			set
			{
				try
				{
					_ID_DataCabang = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_DataCabang", err);
				}
			}
		}
		
		/// <remarks>SQL Type:bit - </remarks>
		private System.Nullable<bool> _KunjunganRutin;
		
		[DisplayName("Kunjungan Rutin")]
		[Category("Column")]
		public System.Nullable<bool> KunjunganRutin
		{
			get
			{
				try
				{
					return _KunjunganRutin;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting KunjunganRutin", err);
				}
			}
			set
			{
				try
				{
					_KunjunganRutin = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting KunjunganRutin", err);
				}
			}
		}
		
		/// <remarks>SQL Type:bit - </remarks>
		private System.Nullable<bool> _TroubleCabang;
		
		[DisplayName("Trouble Cabang")]
		[Category("Column")]
		public System.Nullable<bool> TroubleCabang
		{
			get
			{
				try
				{
					return _TroubleCabang;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting TroubleCabang", err);
				}
			}
			set
			{
				try
				{
					_TroubleCabang = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting TroubleCabang", err);
				}
			}
		}
		
		/// <remarks>SQL Type:bit - </remarks>
		private System.Nullable<bool> _DeploymentUnit;
		
		[DisplayName("Deployment Unit")]
		[Category("Column")]
		public System.Nullable<bool> DeploymentUnit
		{
			get
			{
				try
				{
					return _DeploymentUnit;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting DeploymentUnit", err);
				}
			}
			set
			{
				try
				{
					_DeploymentUnit = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting DeploymentUnit", err);
				}
			}
		}
		
		/// <remarks>SQL Type:bit - </remarks>
		private System.Nullable<bool> _LainLain;
		
		[DisplayName("Lain Lain")]
		[Category("Column")]
		public System.Nullable<bool> LainLain
		{
			get
			{
				try
				{
					return _LainLain;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting LainLain", err);
				}
			}
			set
			{
				try
				{
					_LainLain = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting LainLain", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _DeskripsiKunjungan;
		
		[DisplayName("Deskripsi Kunjungan")]
		[Category("Column")]
		public string DeskripsiKunjungan
		{
			get
			{
				try
				{
					return _DeskripsiKunjungan;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting DeskripsiKunjungan", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_DeskripsiKunjungan = value;
					}
					else
					{
						throw new OverflowException("Error setting DeskripsiKunjungan, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting DeskripsiKunjungan", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _PICHO;
		
		[DisplayName("PICHO")]
		[Category("Column")]
		public string PICHO
		{
			get
			{
				try
				{
					return _PICHO;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting PICHO", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_PICHO = value;
					}
					else
					{
						throw new OverflowException("Error setting PICHO, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting PICHO", err);
				}
			}
		}
		#endregion
		
		#region Related Objects
		/// <remarks>Represents the foreign key object</remarks>
		private Data_Cabang _ID_DataCabang_Data_Cabang;
		
		[Description("Represents the foreign key object of the type Data_Cabang")]
		public Data_Cabang ID_DataCabang_Data_Cabang
		{
			get
			{
				try
				{
					return _ID_DataCabang_Data_Cabang;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID_DataCabang_Data_Cabang", err);
				}
			}
			set
			{
				try
				{
					_ID_DataCabang_Data_Cabang = value;
					_ID_DataCabang = _ID_DataCabang_Data_Cabang.ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID_DataCabang_Data_Cabang", err);
				}
			}
		}
		#endregion
		
		#region Related Object Collections
		/// <remarks>Represents the foreign key object</remarks>
		private Deployment_UnitCollection _Deployment_UnitCollection;
		
		[Description("Represents the foreign key relation. This is an Collection of Data_Kunjungan.")]
		public Deployment_UnitCollection Deployment_UnitCollection
		{
			get
			{
				try
				{
					return _Deployment_UnitCollection;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Deployment_UnitCollection", err);
				}
			}
			set
			{
				try
				{
					_Deployment_UnitCollection = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Deployment_UnitCollection", err);
				}
			}
		}
		
		/// <remarks>Represents the foreign key object</remarks>
		private Trouble_CabangCollection _Trouble_CabangCollection;
		
		[Description("Represents the foreign key relation. This is an Collection of Data_Kunjungan.")]
		public Trouble_CabangCollection Trouble_CabangCollection
		{
			get
			{
				try
				{
					return _Trouble_CabangCollection;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Trouble_CabangCollection", err);
				}
			}
			set
			{
				try
				{
					_Trouble_CabangCollection = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Trouble_CabangCollection", err);
				}
			}
		}
		#endregion
		
		#region Public Methods
		public void Select()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Data_Kunjungan._SQL_Select;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataReader rs = Com.ExecuteReader();
				while(rs.Read())
				{
					AddFromRecordSet(rs);
				}
				rs.Close();
				Conn.Close();
				rs.Dispose();
				Com.Dispose();
				Conn.Dispose();
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public System.Data.DataTable SelectByParam()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Data_Kunjungan._SQL_SelectByParam;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataAdapter objDataAdapter = new SqlDataAdapter(Com);
				DataTable objDataTable = new DataTable();
				objDataAdapter.Fill(objDataTable);
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return objDataTable;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Insert()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Data_Kunjungan._SQL_Insert;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Update()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Data_Kunjungan._SQL_Update;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Delete()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Data_Kunjungan._SQL_Delete;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public string[] GetSqlCommandStrings()
		{
			try
			{
				string[] CommStr = new string[4];
				CommStr[0] = "SELECT [ID], [wfStatus], [Tanggal], [ID_DataCabang], [KunjunganRutin], [TroubleCabang], [DeploymentUnit], [LainLain], [DeskripsiKunjungan], [PICHO] FROM [dbo].[Data Kunjungan] WHERE [ID] = " + _ID + "";
				CommStr[1] = "INSERT INTO [dbo].[Data Kunjungan] ([ID], [wfStatus], [Tanggal], [ID_DataCabang], [KunjunganRutin], [TroubleCabang], [DeploymentUnit], [LainLain], [DeskripsiKunjungan], [PICHO]) VALUES(" + _ID + ", '" + _wfStatus.Replace("'","''") + "', '" + _Tanggal + "', " + _ID_DataCabang + ", " + _KunjunganRutin + ", " + _TroubleCabang + ", " + _DeploymentUnit + ", " + _LainLain + ", '" + _DeskripsiKunjungan.Replace("'","''") + "', '" + _PICHO.Replace("'","''") + "')";
				CommStr[2] = "UPDATE [dbo].[Data Kunjungan] SET [wfStatus] = '" + _wfStatus.Replace("'","''") + "' ,[Tanggal] = '" + _Tanggal + "' ,[ID_DataCabang] = " + _ID_DataCabang + " ,[KunjunganRutin] = " + _KunjunganRutin + " ,[TroubleCabang] = " + _TroubleCabang + " ,[DeploymentUnit] = " + _DeploymentUnit + " ,[LainLain] = " + _LainLain + " ,[DeskripsiKunjungan] = '" + _DeskripsiKunjungan.Replace("'","''") + "' ,[PICHO] = '" + _PICHO.Replace("'","''") + "' WHERE [ID] = " + _ID + "";
				CommStr[3] = "DELETE FROM [dbo].[Data Kunjungan] WHERE [ID] = " + _ID + "";
				return CommStr;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		#endregion
		
		#region Private Methods
		private void AddFromRecordSet(SqlDataReader rs)
		{
			try
			{
				// if value from the recordset, to the ID field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID")) == false))
				{
					ID = rs.GetGuid(rs.GetOrdinal("ID"));
				}
				// if value from the recordset, to the wfStatus field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("wfStatus")) == false))
				{
					wfStatus = rs.GetString(rs.GetOrdinal("wfStatus"));
				}
				// if value from the recordset, to the Tanggal field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Tanggal")) == false))
				{
					Tanggal = rs.GetDateTime(rs.GetOrdinal("Tanggal"));
				}
				// if value from the recordset, to the ID_DataCabang field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID_DataCabang")) == false))
				{
					ID_DataCabang = rs.GetGuid(rs.GetOrdinal("ID_DataCabang"));
				}
				// if value from the recordset, to the KunjunganRutin field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("KunjunganRutin")) == false))
				{
					KunjunganRutin = rs.GetBoolean(rs.GetOrdinal("KunjunganRutin"));
				}
				// if value from the recordset, to the TroubleCabang field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("TroubleCabang")) == false))
				{
					TroubleCabang = rs.GetBoolean(rs.GetOrdinal("TroubleCabang"));
				}
				// if value from the recordset, to the DeploymentUnit field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("DeploymentUnit")) == false))
				{
					DeploymentUnit = rs.GetBoolean(rs.GetOrdinal("DeploymentUnit"));
				}
				// if value from the recordset, to the LainLain field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("LainLain")) == false))
				{
					LainLain = rs.GetBoolean(rs.GetOrdinal("LainLain"));
				}
				// if value from the recordset, to the DeskripsiKunjungan field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("DeskripsiKunjungan")) == false))
				{
					DeskripsiKunjungan = rs.GetString(rs.GetOrdinal("DeskripsiKunjungan"));
				}
				// if value from the recordset, to the PICHO field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("PICHO")) == false))
				{
					PICHO = rs.GetString(rs.GetOrdinal("PICHO"));
				}
			}
			catch (SqlException sqlExc)
			{
				throw sqlExc;
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		
		private SqlParameter[] GetSqlParameters()
		{
			List<SqlParameter> SqlParmColl = new List<SqlParameter>();
			try
			{
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID", ID, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@wfStatus", wfStatus, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Tanggal", Tanggal, SqlDbType.DateTime));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID_DataCabang", ID_DataCabang, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@KunjunganRutin", KunjunganRutin, SqlDbType.Bit));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@TroubleCabang", TroubleCabang, SqlDbType.Bit));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@DeploymentUnit", DeploymentUnit, SqlDbType.Bit));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@LainLain", LainLain, SqlDbType.Bit));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@DeskripsiKunjungan", DeskripsiKunjungan, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@PICHO", PICHO, SqlDbType.VarChar));
				return SqlParmColl.ToArray();
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		#endregion
	}
	
	public class Data_KunjunganCollection : System.Collections.CollectionBase
	{
		
		[Description("Adds a new Data_Kunjungan to the collection.")]
		public int Add(Data_Kunjungan item)
		{
			int newindex = List.Add(item);
			return newindex;
		}
		
		[Description("Removes a Data_Kunjungan from the collection.")]
		public void Remove(Data_Kunjungan item)
		{
			List.Remove(item);
		}
		
		[Description("Inserts an Data_Kunjungan into the collection at the specified index.")]
		public void Insert(int index, Data_Kunjungan item)
		{
			List.Insert(index, item);
		}
		
		[Description("Returns the index value of the Data_Kunjungan class in the collection.")]
		public int IndexOf(Data_Kunjungan item)
		{
			return List.IndexOf(item);
		}
		
		[Description("Returns true if the Data_Kunjungan class is present in the collection.")]
		public bool Contains(Data_Kunjungan item)
		{
			return List.Contains(item);
		}
	}
	
	public enum Data_Kunjungan_Fields
	{
		
		ID,
		
		wfStatus,
		
		Tanggal,
		
		ID_DataCabang,
		
		KunjunganRutin,
		
		TroubleCabang,
		
		DeploymentUnit,
		
		LainLain,
		
		DeskripsiKunjungan,
		
		PICHO,
	}
}
